package com.das.mechanic_webview.view.ground;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.webkit.WebSettings;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.das.mechanic_base.R2;
import com.das.mechanic_base.adapter.main.X3BottomHomeCarAndColorAdapter;
import com.das.mechanic_base.app.X3AppRouterConstants;
import com.das.mechanic_base.app.X3Constent;
import com.das.mechanic_base.app.X3MyApp;
import com.das.mechanic_base.app.X3RouterCenter;
import com.das.mechanic_base.base.X3BaseActivity;
import com.das.mechanic_base.base.X3IBaseView;
import com.das.mechanic_base.bean.alone.CloseWebviewAcivityBean;
import com.das.mechanic_base.bean.even.CrmVpSumEvenBus;
import com.das.mechanic_base.bean.even.DeleteFriends;
import com.das.mechanic_base.bean.ground.CancelBean;
import com.das.mechanic_base.bean.ground.CarPropertiesBean;
import com.das.mechanic_base.bean.ground.GroundPushBean;
import com.das.mechanic_base.bean.ground.InputBean;
import com.das.mechanic_base.bean.ground.MainSuccessBean;
import com.das.mechanic_base.bean.ground.ShareWorkBean;
import com.das.mechanic_base.bean.ground.UserCarInfoBean;
import com.das.mechanic_base.bean.ground.VehicleInfoBean;
import com.das.mechanic_base.bean.live.LiveRoomDetailBean;
import com.das.mechanic_base.bean.main.AppointBean;
import com.das.mechanic_base.bean.main.AppointClueBean;
import com.das.mechanic_base.bean.main.CarBrandAndCommonBean;
import com.das.mechanic_base.bean.main.CarBrandBean;
import com.das.mechanic_base.bean.main.CarModelSelectBean;
import com.das.mechanic_base.bean.main.CarOwnerDaoBean;
import com.das.mechanic_base.bean.main.CarPicAndColorBean;
import com.das.mechanic_base.bean.main.CarSelectBean;
import com.das.mechanic_base.bean.main.GiftBalanceBean;
import com.das.mechanic_base.bean.main.HomeMainCarBean;
import com.das.mechanic_base.bean.main.JumpToWorkBase;
import com.das.mechanic_base.bean.plan.PlanListBean;
import com.das.mechanic_base.bean.task.AloneShareParamsBean;
import com.das.mechanic_base.bean.task.CheckTaskBean;
import com.das.mechanic_base.bean.task.InitialnspectionBean;
import com.das.mechanic_base.bean.task.ServiceCreateTask;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.mvp.view.create.X3FirstAloneActivity;
import com.das.mechanic_base.mvp.view.finish.X3WorkFinishActivity;
import com.das.mechanic_base.utils.LanguageUtiles;
import com.das.mechanic_base.utils.ThreadPoolManager;
import com.das.mechanic_base.utils.WebViewPool;
import com.das.mechanic_base.utils.X3BottomChangePlanDialog;
import com.das.mechanic_base.utils.X3FileUtils;
import com.das.mechanic_base.utils.X3ImgDownload;
import com.das.mechanic_base.utils.X3ScreenUtils;
import com.das.mechanic_base.utils.X3StatusBarUtil;
import com.das.mechanic_base.utils.X3StringUtils;
import com.das.mechanic_base.utils.X3ToastUtils;
import com.das.mechanic_base.utils.X3Utils;
import com.das.mechanic_base.utils.X3WebViewBugUtil;
import com.das.mechanic_base.widget.X3AndroidJAInteface;
import com.das.mechanic_base.widget.X3AppearanceamageDialog;
import com.das.mechanic_base.widget.X3BitmapUtils;
import com.das.mechanic_base.widget.X3BottomAloneThingDialog;
import com.das.mechanic_base.widget.X3BottomGiftBalanceDialog;
import com.das.mechanic_base.widget.X3BottomHomeCarDialog;
import com.das.mechanic_base.widget.X3BottomHomeCarOwnerTextDialog;
import com.das.mechanic_base.widget.X3BottomHomeCarPaintDialog;
import com.das.mechanic_base.widget.X3BottomHomeCarPicAndColorDialog;
import com.das.mechanic_base.widget.X3BottomHomeTyreDialog;
import com.das.mechanic_base.widget.X3BottomPrecentPickerDialog;
import com.das.mechanic_base.widget.X3BottomServiceAppointDialog;
import com.das.mechanic_base.widget.X3BottomTimeAppointDialog;
import com.das.mechanic_base.widget.X3DashboardWarningLightsDialog;
import com.das.mechanic_base.widget.X3HomeBrandSelectDialog;
import com.das.mechanic_base.widget.X3HomeChangeMileDialog;
import com.das.mechanic_base.widget.X3HomeStyleSelectDialog;
import com.das.mechanic_base.widget.X3HomeTimeSelectDialog;
import com.das.mechanic_base.widget.X3InputPopWindow;
import com.das.mechanic_base.widget.X3NewBottomMileOrTimeDialog;
import com.das.mechanic_base.widget.X3NewWebView;
import com.das.mechanic_base.widget.X3TaskInputPopWindow;
import com.das.mechanic_base.widget.X3TipsDialog;
import com.das.mechanic_webview.R;
import com.das.mechanic_webview.contract.ground.X3GroundPushContract;
import com.das.mechanic_webview.presenter.ground.X3GroundPushPresenter;
import com.das.mechanic_webview.view.report.X3ReportActivity;
import com.google.gson.Gson;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.umeng.analytics.MobclickAgent;
import com.yhao.floatwindow.FloatWindow;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import razerdp.basepopup.BasePopupWindow;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

import static android.os.Build.VERSION_CODES.KITKAT;

/**
 * 我的地推
 */
@Route(path = X3AppRouterConstants.Router.GROUND_PUSH)
public class X3GroundPushActivity extends X3BaseActivity<X3GroundPushPresenter> implements X3GroundPushContract.View, X3AndroidJAInteface.IOnClickVisit, X3AndroidJAInteface.IOnClickCreate, X3AndroidJAInteface.IOnClickMessage, X3AndroidJAInteface.IOnClickAppoint, X3BottomServiceAppointDialog.IOnClickSelect, X3BottomTimeAppointDialog.IOnClickTime, X3AndroidJAInteface.IOnClickJumpWork, X3AndroidJAInteface.IOClickGiftBalance, X3AndroidJAInteface.IOnDownFile, X3BottomHomeCarDialog.IOnClickCar, X3HomeTimeSelectDialog.IOnClickCar, X3InputPopWindow.IOnSendContent, X3BottomChangePlanDialog.IOnRefreshPlan, WebViewPool.WebViewSettingListener {

    @BindView(R2.id.layout)
    RelativeLayout layout;

    ProgressBar psb;

    X3NewWebView mWebView;
    private static final int CREATE_TASK_START = 1001;

    private Gson gson;
    private String carListId;
    private String mobile;
    private X3BottomServiceAppointDialog appointDialog;
    private boolean isAppoint;
    private X3BottomTimeAppointDialog timeAppointDialog;
    private boolean isDark;
    private GroundPushBean pushBean;
    public static X3GroundPushActivity instance = null;
    private X3BottomGiftBalanceDialog bottomGiftBalanceDialog;//赠送余额
    private int type;

    private int h5Height = 0;

    private boolean isFirstLoad;

    private boolean isEnable;

    private int carOwnerNameUserId;//赠送余额的时候，将这个id一直传下去，提交的时候需要用到
    private String webUrl;
    private X3BottomHomeCarDialog homeCarDialog;

    private String carNum;
    private boolean detectionFirstOrNot;
    private VehicleInfoBean infoBean;
    private X3HomeBrandSelectDialog brandSelectDialog;
    private List<CarBrandBean> brandList;
    private X3HomeStyleSelectDialog styleSelectDialog;
    private List<CarBrandBean> carStyleList;
    private String reloadStr;
    private List<CarPicAndColorBean> carPicList;

    private int allNum,cuteNum;
    private Bitmap img_6;
    private X3BottomHomeCarPicAndColorDialog picAndColorDialog;
    private String lastCutPath;
    private boolean isToast;

    private int carowneruserCommunicationId = 0;
    private X3InputPopWindow mPopupInput;
    private InputBean inputBean;
    private X3TaskInputPopWindow taskInput;
    private String title;
    private boolean isShow ;
    private int screenWidth;
    private int screenHeight;
    private String captureHeight;
    private X3TipsDialog shareDialog;
    private X3BottomChangePlanDialog planDialog;
    private X3AndroidJAInteface androidJAInteface;

    private Handler mPlayBackHandler = new Handler();

    //截屏分享，h5向原生传递的参数
    AloneShareParamsBean aloneShareParamsBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        WebViewPool.init(this);
        super.onCreate(savedInstanceState);
        WebViewPool.startTime = System.currentTimeMillis();
        Log.e("MyBrowserViewClient!@#","onCreate" + WebViewPool.startTime);

    }

    @Override
    protected int getLayoutId() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
//        StatusBarUtil.darkMode(this);

        isFirstLoad = true;
        mWebView = WebViewPool.getInstance().getWebView(this);

        String path = getIntent().getStringExtra("path");

        webUrl = getIntent().getStringExtra("webUrl");

        Log.e("qqqq","加载:" + path + "::" + webUrl);
        WebViewPool.getInstance().synchronousWebCookies(this, X3Constent.getH5BaseUrl());
        if (X3StringUtils.isEmpty(path)) {
            mWebView.loadUrl(webUrl);
        } else {
            mWebView.loadUrl(X3Constent.getH5BaseUrl() + path);
        }

        initWebViewSet();
        return R.layout.x3_activity_ground_push;
    }

    @Override
    protected void initView() {
        WebViewPool.getInstance().startTime = System.currentTimeMillis();
        isShow = true;
        getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);

        isDark = getIntent().getBooleanExtra("isDark", false);
        X3StatusBarUtil.darkMode(this);
//        if (!StringUtils.isEmpty(webUrl) && webUrl.contains(Constent.HOME_FINISH_DETAIL_MAIN_URL)) {
//            StatusBarUtil.darkMode(this, false);
//        }else {
//            StatusBarUtil.darkMode(this, isDark);
//        }

        img_6 = X3ImgDownload.getImageFromAssetsFile("img_6.png", this);

        gson = new Gson();
        layout.addView(mWebView);
        ViewGroup.LayoutParams layoutParams = mWebView.getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        mWebView.setLayoutParams(layoutParams);

        RelativeLayout rl = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.x3_activity_ground_push_progresbar,null);
        psb = rl.findViewById(R.id.psb);
        int barH = X3StatusBarUtil.getStatusBarHeight(this) + X3ScreenUtils.dipToPx(5, this);
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) psb.getLayoutParams() ;
        lp.topMargin = barH;
        psb.setLayoutParams(lp);

        psb.setProgress(0);

        layout.addView(rl);

        WebViewPool.MyBrowserChromeClient  myBrowserChromeClient = null;
        WebViewPool.MyBrowserViewClient myBrowserViewClient = null;
        if (mWebView.getWebChromeClient() instanceof  WebViewPool.MyBrowserChromeClient){
            myBrowserChromeClient = (WebViewPool.MyBrowserChromeClient) mWebView.getWebChromeClient();
            myBrowserChromeClient.webViewSettingListener = this;
        }
        if (mWebView.getWebViewClient() instanceof  WebViewPool.MyBrowserViewClient){
            myBrowserViewClient = (WebViewPool.MyBrowserViewClient) mWebView.getWebViewClient();
            myBrowserViewClient.webViewSettingListener = this;
        }

        X3WebViewBugUtil.assistActivity(this);

        setDrawDuringWindowsAnimating(layout);

        instance = this;
        type = getIntent().getIntExtra("type", 0);
        title = getIntent().getStringExtra("title");

    }

    //记录原始窗口高度
    private int mWindowHeight = 0;

    private ViewTreeObserver.OnGlobalLayoutListener mGlobalLayoutListener = () -> {
        Rect rect = new Rect();
        //获取当前窗口实际的可见区域
        getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);

        int height = rect.height();

        if (mWindowHeight == 0) {
            //一般情况下，这是原始的窗口高度
            mWindowHeight = height;
            if (mPopupInput != null) {
                mPopupInput.dismiss();
            }
        } else {
            if (mWindowHeight == height) {
                if (mPopupInput != null) {
                    mPopupInput.dismiss();
                }
            }
        }
    };

    @SuppressLint("SetJavaScriptEnabled")
    public void initWebViewSet() {
        androidJAInteface = new X3AndroidJAInteface(X3GroundPushActivity.this, mWebView);
        mWebView.addJavascriptInterface(androidJAInteface, "member");

        androidJAInteface.setiOnShowHeaderColor(color -> mWebView.post(() -> {
            if ("white".equals(color)) {
                X3StatusBarUtil.darkMode(X3GroundPushActivity.this,false);
            }else if ("black".equals(color)) {
                X3StatusBarUtil.darkMode(X3GroundPushActivity.this,true);
            }
        }));
        androidJAInteface.setiOnRefreshLoad(() -> mWebView.post(() -> {
            DeleteFriends deleteFriends = new DeleteFriends("refresh");
            EventBus.getDefault().post(deleteFriends);

        }));

        //直播回放
        androidJAInteface.setIOnLivePlayBack(new X3AndroidJAInteface.IOnLivePlayBack() {
            @Override
            public void iOnLivePlayBack(int roomId) {
                mPlayBackHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        X3GroundPushActivity.this.showLoading("");
                    }
                });
                NetWorkHttp.getApi().getHistoryLiveRoomDetail(roomId)
                        .compose(RxSchedulersHelper.defaultComposeRequest())
                        .subscribe(new HttpCallBack<LiveRoomDetailBean>() {
                            @Override
                            protected void onDone(LiveRoomDetailBean detailBean) {
                                mPlayBackHandler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        X3GroundPushActivity.this.hideLoading();
                                    }
                                });
                                List<LiveRoomDetailBean.CameraListBean> list = detailBean.cameraList;

                                if (!X3StringUtils.isListEmpty(list)){
                                    Bundle bundle = new Bundle();
                                    bundle.putSerializable("info",list.get(0));
                                    bundle.putBoolean("isPlayBack",true);
                                    X3RouterCenter.startNavigate(X3AppRouterConstants.Router.LIVE_PLAY,bundle);
                                }

                            }

                            @Override
                            protected String LoadingMessage() {
                                mPlayBackHandler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        X3GroundPushActivity.this.hideLoading();
                                    }
                                });
                                return null;
                            }

                            @Override
                            protected void showError(String error) {
                                mPlayBackHandler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        X3GroundPushActivity.this.hideLoading();
                                    }
                                });
                            }
                        });
            }
        });

        // 施工报告分享
        androidJAInteface.setiOnShareWork(json -> {
            if (X3StringUtils.isEmpty(json)) {
                return;
            }
            mWebView.post(() -> {
                ShareWorkBean shareWorkBean = gson.fromJson(json, ShareWorkBean.class);
                if (shareWorkBean == null) {
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putSerializable("workShare",shareWorkBean);
                X3RouterCenter.startNavigate(X3AppRouterConstants.Router.WORK_CAPTURE,bundle);
                X3GroundPushActivity.this.overridePendingTransition(R.anim.activity_top_enter,0);

            });
        });

        // 编辑保养和维修计划
        androidJAInteface.setiOnEditPlan(json -> mWebView.post(() -> {
            PlanListBean detailBean = new Gson().fromJson(json,PlanListBean.class);
            if (planDialog == null) {
                planDialog = new X3BottomChangePlanDialog(X3GroundPushActivity.this);
            }
            planDialog.show();
            planDialog.showChangePlan(detailBean);
            planDialog.setiOnRefreshPlan(X3GroundPushActivity.this);
        }));

        androidJAInteface.setiOnUpdateVehicleInfo(() -> mWebView.post(() -> {
//            DeleteFriends friends = new DeleteFriends("Refresh_Crm");
//            EventBus.getDefault().post(friends);
        }));

        androidJAInteface.setiOnUpdateWorkList(() -> mWebView.post(() -> EventBus.getDefault().post("Refresh_Home")));

        // 关闭手势返回
        androidJAInteface.setiOnDisable(new X3AndroidJAInteface.IOnDisable() {
            @Override
            public void iOnDisableGestures() {
                mWebView.post(() -> {
                    swipeBackLayout.setEnableGesture(false);
                    isEnable = true;
                });

            }

            @Override
            public void iOnEnableGestures() {
                mWebView.post(() -> {
                    swipeBackLayout.setEnableGesture(true);
                    isEnable = false;
                });
            }
        });

        androidJAInteface.setiOnShareScreen(shareScreen -> {
            aloneShareParamsBean = gson.fromJson(shareScreen, AloneShareParamsBean.class);
            mWebView.post(() -> screenGetBitmap());
        });
        androidJAInteface.setiOnInputContent(pushBean -> mWebView.post(() -> {
            if (pushBean == null) {
                return;
            }
            X3GroundPushActivity.this.inputBean = pushBean;
            if (mPopupInput == null) {
                mPopupInput = new X3InputPopWindow(X3GroundPushActivity.this);
            }
            mPopupInput.setAdjustInputMethod(true)
                    .setBackPressEnable(true)
                    .setAutoShowInputMethod(mPopupInput.findViewById(R.id.ed_input), true)
                    .setAdjustInputMode(R.id.ed_input, BasePopupWindow.FLAG_KEYBOARD_ALIGN_TO_ROOT | BasePopupWindow.FLAG_KEYBOARD_ANIMATE_ALIGN)
                    .showPopupWindow();
            mPopupInput.showType(pushBean.type,pushBean.value,pushBean.limit);
            mPopupInput.setiOnSendContent(X3GroundPushActivity.this);

        }));

        // 即将保存留言 要弹起软键盘
        androidJAInteface.setiOnShowSaveCommun(carowneruserCommunicationId -> {
            mWebView.post(() -> {
                X3GroundPushActivity.this.carowneruserCommunicationId = carowneruserCommunicationId;
                if (mPopupInput == null) {
                    mPopupInput = new X3InputPopWindow(X3GroundPushActivity.this);
                }
                mPopupInput.setAdjustInputMethod(true)
                        .setBackPressEnable(true)
                        .setAutoShowInputMethod(mPopupInput.findViewById(R.id.ed_input), true)
                        .setAdjustInputMode(R.id.ed_input, BasePopupWindow.FLAG_KEYBOARD_ALIGN_TO_ROOT | BasePopupWindow.FLAG_KEYBOARD_ANIMATE_ALIGN)
                        .showPopupWindow();
                mPopupInput.showType("0","",0);
                mPopupInput.setiOnSendContent(this);

            });
        });

        // TODO 初检交互
        androidJAInteface.setiOnShowAlone(jsonBean -> mWebView.post(() -> {

            InitialnspectionBean initialnspectionBean = gson.fromJson(jsonBean, InitialnspectionBean.class);

            Intent intent = new Intent(this, X3FirstAloneActivity.class);
            intent.putExtra("receiveBaseId",initialnspectionBean.receiveBaseId);
            startActivity(intent);
        }));

        // 车辆切割 缩略图
        androidJAInteface.setiOnShowCarPicCut(pushBean -> {
            mWebView.post(() -> {
                if (pushBean == null) {
                    return;
                }
                String carId = pushBean.getCarId();
                String carStyleId = pushBean.getCarStyleId();
                String carNum = pushBean.getCarNum();
                long colorId = pushBean.getColorId();
                long carPicTempletId = pushBean.getCarPicTempletId();

                if (X3StringUtils.isEmpty(carId)) {
                    return;
                }

                if (picAndColorDialog == null) {
                    picAndColorDialog = new X3BottomHomeCarPicAndColorDialog(X3GroundPushActivity.this);
                    getCarPicAndColor(Long.parseLong(carId),Long.parseLong(carStyleId),carNum,colorId,carPicTempletId);

                }
                picAndColorDialog.show();
                picAndColorDialog.setOnDismissListener(dialog -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));
                if (isToast) {
                    picAndColorDialog.changeNoToast();
                    isToast = false;
                }
                picAndColorDialog.changeSelectColor(colorId,carPicTempletId);
                picAndColorDialog.sendCarId(Integer.parseInt(carId));
                picAndColorDialog.setNextCarPic(new X3BottomHomeCarPicAndColorDialog.IOnNextCarPic() {
                    @Override
                    public void iOnNextGetCarPic(CarPicAndColorBean carPicAndColorBean, String carMove, int position) {
                        if (carPicAndColorBean == null) {
                            return;
                        }

                        String replace = carPicAndColorBean.toString().replace("\"", "\'");

                        Log.e("replace_","replace1_ = " + replace );

                        mWebView.post(new Runnable() {
                            @Override
                            public void run() {
                                mWebView.evaluateJavascript("window.setCarPic(\"" + replace + "\")",
                                        value -> Log.e("调用setCarPic", value + "-----"));
                            }
                        });

                    }

                    @Override
                    public void iOnNextSelectPic(CarPicAndColorBean carPicAndColorBean) {
                        if (carPicAndColorBean == null) {
                            return;
                        }

                        String replace = carPicAndColorBean.toString().replace("\"", "\'");
                        Log.e("replace_","replace2_ = " + replace );
                        mWebView.post(new Runnable() {
                            @Override
                            public void run() {
                                mWebView.evaluateJavascript("window.setCarPic(\"" + replace + "\")",
                                        value -> Log.e("调用setCarPic", value + "-----"));
                            }
                        });

                    }
                });
            });
        });
        // 生成车辆码
        androidJAInteface.setiOnShowCarBind(pushBean -> {
            if (pushBean == null) {
                return;
            }
            String carId = pushBean.getCarId();
            if (X3StringUtils.isEmpty(carId)) {
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putLong("carId",Long.parseLong(carId));
            X3RouterCenter.startNavigate(X3AppRouterConstants.Router.CAR_BIND_CODE,bundle);

        });

        // 双轨计算
        androidJAInteface.setiOnShowToDueDate(mileOrTimeBean -> {
            if (mileOrTimeBean == null) {
                return;
            }

            mWebView.post(() -> {
                X3NewBottomMileOrTimeDialog mileOrTimeDialog = new X3NewBottomMileOrTimeDialog(X3GroundPushActivity.this,1);
                mileOrTimeDialog.show();
                mileOrTimeDialog.modifyCurrentMiles(mileOrTimeBean.currentMiles,mileOrTimeBean.perMiles,mileOrTimeBean.nextReplaceCycleKm,mileOrTimeBean.reductionType,mileOrTimeBean.date);
                mileOrTimeDialog.setiOnAffirmMile((time, nextMiles, type) -> {
//                    DeleteFriends friends = new DeleteFriends("Refresh_Crm");
//                    EventBus.getDefault().post(friends);
                    mileOrTimeBean.date = time;
                    mileOrTimeBean.nextMile = nextMiles;
                    mileOrTimeBean.reductionType = (type == 0) ? "MILE" : "TIME";
                    mWebView.loadUrl("javascript:nativeToGetDueDateBack(" + mileOrTimeBean.toString() + ")");
                });
            });
        });

        /**
         * 车辆详情 车辆品牌 车款 出厂时间
         */
        androidJAInteface.setiOnShowVehicleInfo(infoBean -> {
            if (infoBean == null) {
                return;
            }
            String type = infoBean.type;
            if (X3StringUtils.isEmpty(type)) {
                return;
            }
            X3GroundPushActivity.this.infoBean = infoBean;
            switch (type) {
                case "carBrand":
                    getCarBrandData();
                    break;
                case "manufactureDate":
                    X3HomeTimeSelectDialog timeSelectDialog = new X3HomeTimeSelectDialog(X3GroundPushActivity.this);
                    timeSelectDialog.show();
                    String value = infoBean.value;
                    if (!X3StringUtils.isEmpty(value)) {
                        String[] split = value.split("-");
                        if (split != null && split.length >= 2) {
                            if (!"undefined".equals(split[0]) && !"undefined".equals(split[1])) {
                                timeSelectDialog.setNewSelect(Integer.parseInt(split[0]), split[1]);
                            } else {
                                timeSelectDialog.setNewSelect(2012, "01");
                            }
                        }
                    }
                    timeSelectDialog.setiOnClick(X3GroundPushActivity.this);
                    break;
            }
        });
        /**
         * 车辆详情 车辆品牌 车款 出厂时间
         */
        androidJAInteface.setiOnShowVehicleInfo(infoBean -> mWebView.post(() -> {
            if (infoBean == null) {
                return;
            }
            String type = infoBean.type;
            if (X3StringUtils.isEmpty(type)) {
                return;
            }
            X3GroundPushActivity.this.infoBean = infoBean;
            switch (type) {
                case "carBrand":
                    getCarBrandData();
                    break;
                case "carAge":
                case "manufactureDate":
                    X3HomeTimeSelectDialog timeSelectDialog = new X3HomeTimeSelectDialog(X3GroundPushActivity.this);
                    timeSelectDialog.show();
                    String value = infoBean.value;
                    if (!X3StringUtils.isEmpty(value)) {
                        String[] split = value.split("-");
                        if (split != null && split.length >= 2) {
                            if (!"undefined".equals(split[0]) && !"undefined".equals(split[1])) {
                                timeSelectDialog.setNewSelect(Integer.parseInt(split[0]),split[1]);
                            }else {
                                timeSelectDialog.setNewSelect(2012,"01");
                            }
                        }
                    }
                    timeSelectDialog.setiOnClick(X3GroundPushActivity.this);
                    break;
            }
        }));

        /**
         * 如果需要重新赋值车辆车型数据 因为之前发生了导入覆盖数据
         */
        androidJAInteface.setiOnClickUpdateCar(carTypeBean -> mWebView.post(() -> {
            if (carTypeBean == null) {
                return;
            }
            carNum = carTypeBean.carNum;
            if(homeCarDialog != null && homeCarDialog.isShowing()){
                return;
            }
            homeCarDialog = new X3BottomHomeCarDialog(X3GroundPushActivity.this);
            homeCarDialog.show();
            homeCarDialog.setReceiveId(carTypeBean.id,carTypeBean.carNum);
            homeCarDialog.setChangeCarType();
            homeCarDialog.setiOnClick(X3GroundPushActivity.this);
            //获取接车单数据
            if (mPresenter != null) {
                mPresenter.getReceiveBase(carTypeBean.id);
            }
        }));

        /**
         * 初检交互
         */
        androidJAInteface.setiOnClickAlone(aloneBean -> mWebView.post(() -> {
            if (aloneBean == null) {
                return;
            }
            if ("sys_oil_001".equals(aloneBean.sn)) {
                List<String> oilList = new ArrayList<>();
                for (int i = 0; i <= 10; i++) {
                    oilList.add(i * 10 + "");
                }

                String oil = aloneBean.oil;
                if (X3StringUtils.isEmpty(oil)) {
                    oil = "100";
                }
                X3BottomPrecentPickerDialog precentPickerDialog = new X3BottomPrecentPickerDialog(X3GroundPushActivity.this);
                precentPickerDialog.show();
                precentPickerDialog.showContent(oil,oilList,aloneBean.toSystem);
                precentPickerDialog.setiOnItemCameraClick(new X3BottomPrecentPickerDialog.IOpenNumberClick() {
                    @Override
                    public void iOpenCancelListener() {

                    }

                    @Override
                    public void iOpenAffirmListener(String selectData) {
                        if (mPresenter != null) {
                            mPresenter.saveOrUpdateOil(selectData,aloneBean.receiveBaseId);
                        }
                    }
                });

            }else if ("sys_tyre_001".equals(aloneBean.sn)) {
                X3BottomHomeTyreDialog tyreDialog = new X3BottomHomeTyreDialog(X3GroundPushActivity.this);
                tyreDialog.show();
                tyreDialog.setQuestionSystemSn(aloneBean.sn,aloneBean.receiveBaseId);
                tyreDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }else if ("sys_paint_001".equals(aloneBean.sn)) {
                X3BottomHomeCarPaintDialog carPaintDialog = new X3BottomHomeCarPaintDialog(X3GroundPushActivity.this);
                carPaintDialog.show();
                carPaintDialog.setQuestionSystemSn(aloneBean.sn,aloneBean.receiveBaseId);
                carPaintDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }else if ("sys_remark_001".equals(aloneBean.sn)) {
                X3BottomHomeCarOwnerTextDialog carOwnerTextDialog = new X3BottomHomeCarOwnerTextDialog(X3GroundPushActivity.this);
                carOwnerTextDialog.show();
                carOwnerTextDialog.setContentText("");
                carOwnerTextDialog.showReceiveBaseId(aloneBean.receiveBaseId,aloneBean.toSystem);
                carOwnerTextDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }else if ("sys_thing_001".equals(aloneBean.sn)) {
                X3BottomAloneThingDialog thingDialog = new X3BottomAloneThingDialog(X3GroundPushActivity.this);
                thingDialog.show();
                thingDialog.setQuestionSystemSn("",aloneBean.receiveBaseId);
                thingDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }else if  ("sys_light_001".equals(aloneBean.sn)){//故障灯
                X3DashboardWarningLightsDialog dashboardWarningLightsDialog = new X3DashboardWarningLightsDialog(X3GroundPushActivity.this);
                dashboardWarningLightsDialog.setDialogTitle(aloneBean.toSystem);
                dashboardWarningLightsDialog.show();
                dashboardWarningLightsDialog.from(0);
                dashboardWarningLightsDialog.setDetailSystemSn(aloneBean.sn,aloneBean.receiveBaseId,aloneBean.carId);
                dashboardWarningLightsDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }else if  ("sys_feature_001".equals(aloneBean.sn)){//车损外观
                X3AppearanceamageDialog appearanceamageDialog = new X3AppearanceamageDialog(X3GroundPushActivity.this);
                appearanceamageDialog.setDialogTitle(aloneBean.toSystem);
                appearanceamageDialog.show();
                appearanceamageDialog.from(0);
                appearanceamageDialog.setDetailSystemSn(aloneBean.sn,aloneBean.receiveBaseId,aloneBean.carId);
                appearanceamageDialog.setiOnRefresh(() -> mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {}));

            }
        }));

        androidJAInteface.setiOnShowCar(carId -> {
            Message message = Message.obtain();
            message.what = 0;
            message.obj = carId;
            mHandler.sendMessage(message);
        });

        androidJAInteface.setiOnRequest(carNumOrVin -> {
            XXPermissions.with(this)
                    .permission(Permission.Group.STORAGE)
                    .permission(Permission.CAMERA)
                    .request(new OnPermissionCallback() {
                        @Override
                        public void onGranted(List<String> permissions, boolean all) {
                            if(all){
                                goToHomeCamera(carNumOrVin);
                            }else {
                                XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                            }
                        }

                        @Override
                        public void onDenied(List<String> permissions, boolean never) {
                            XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                        }
                    });

        });

        // 返回到第几个页面
        androidJAInteface.setiOnBackWebview(step -> mWebView.post(() -> {
            if (X3StringUtils.isListEmpty(X3MyApp.mActivities)) {
                return;
            }
            int flag = 0;
            for (int i = 0; i < X3MyApp.mActivities.size(); i++) {
                if (X3MyApp.mActivities.get(i) instanceof X3GroundPushActivity) {
                    flag++;
                    if (flag > 1) {
                        X3MyApp.mActivities.get(i).finish();
                    }else {
                        ((X3GroundPushActivity) X3MyApp.mActivities.get(i)).loadRefresh();
                    }
                }
            }
        }));

        androidJAInteface.setiOnClickCRM(() -> {
            //用户在详情更改头像之后，通知crm客户详情刷新数据
            EventBus.getDefault().post(new CrmVpSumEvenBus());
        });

        androidJAInteface.setiOnClickCreateTask(new X3AndroidJAInteface.IOnClickCreateTask() {
            @Override
            public void iOnClickCreateTask(String serviceBase) {
                mWebView.post(() -> {
                    if (X3StringUtils.isEmpty(serviceBase)) {
                        //ToastUtils.showMessage(getString(R.string.task_create_error));
                        return;
                    }
                    ServiceCreateTask serviceCreateTask = gson.fromJson(serviceBase, ServiceCreateTask.class);

                    if (taskInput == null) {
                        taskInput = new X3TaskInputPopWindow(X3GroundPushActivity.this);
                    }
                    taskInput.show();
                    taskInput.showTaskInput(false,false,false,true,0,serviceCreateTask);
                });

            }

            @Override
            public void iOnClickCheckTask(String taskId) {
                mWebView.post(() -> {

                    if (X3StringUtils.isEmpty(taskId)) {
                        return;
                    }
                    CheckTaskBean checkTaskBean = gson.fromJson(taskId, CheckTaskBean.class);

                    if (taskInput == null) {
                        taskInput = new X3TaskInputPopWindow(X3GroundPushActivity.this);
                    }
                    taskInput.show();
                    taskInput.showTaskInput(true,false,false,true,checkTaskBean.getTaskId(),null);
                });

            }
        });

        androidJAInteface.setiOnBackReload(params -> {
            if ("0".equals(params)) {
                mWebView.post(() -> {
                    if (mWebView != null && mWebView.canGoBack()) {
                        mWebView.goBack();
                    } else {
                        EventBus.getDefault().post("UPDATE_START_ORDER");
                        finish();
                    }
                });
            }else if("1".equals(params)) {
                mWebView.post(() -> {
                    EventBus.getDefault().post("UPDATE_START_ORDER");
                    finish();
                });
            } else {
//                mWebView.post(() -> mWebView.loadUrl("javascript:reloadPage(" + params + ")"));
                Intent intent = getIntent();
                intent.putExtra("path",params);
                setResult(Activity.RESULT_OK,intent);
                finish();
            }
        });

        androidJAInteface.setiOnCLickPushReport(url -> {
            if ("0".equals(url)) {
                mWebView.post(() -> {
                    if (mWebView.canGoBack()) {
                        mWebView.goBack();
                    } else {
                        EventBus.getDefault().post("UPDATE_START_ORDER");
                        finish();
                    }
                });
            } else {
                Intent intent = new Intent(X3GroundPushActivity.this, X3GroundPushActivity.class);
                intent.putExtra("webUrl", url);
                intent.putExtra("isDark", true);
                startActivityForResult(intent,3333);
                overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            }
        });

        // 取消
        androidJAInteface.setiOnClickUpdatePage(jumpSuccess -> {
            if (X3StringUtils.isEmpty(jumpSuccess)) {
                return;
            }
            CancelBean workBean = gson.fromJson(jumpSuccess, CancelBean.class);
            if (workBean == null) {
                return;
            }
            if ("work".equals(workBean.page)) {
                EventBus.getDefault().post("UPDATE_START_ORDER");
                finish();
            }
        });

        // 施工 或者 检测
        androidJAInteface.setiOnClickJumpToSuccess(jumpSuccess -> {
            if (X3StringUtils.isEmpty(jumpSuccess)) {
                X3ToastUtils.showMessage(getString(R.string.x3_server_http_error));
                return;
            }
            MainSuccessBean successBean = gson.fromJson(jumpSuccess, MainSuccessBean.class);
            if (successBean == null) {
                return;
            }

            Intent intent = new Intent(this, X3WorkFinishActivity.class);
            intent.putExtra("workBaseId", successBean.getId());
            intent.putExtra("carId", successBean.getCarId());
            intent.putExtra("type", type);
            intent.putExtra("carNum", successBean.getCarNum());
            startActivity(intent);
        });

        androidJAInteface.setiOnH5Height(h5Height -> {
            X3GroundPushActivity.this.h5Height = h5Height;
        });

        //日均里程弹窗
        androidJAInteface.setiOnShowHomeChangeDialog((totalMile, modelTime, customSet, permile) -> {
            mWebView.post(() -> {
                X3HomeChangeMileDialog changeMileDialog = new X3HomeChangeMileDialog(X3GroundPushActivity.this);
                changeMileDialog.show();
                changeMileDialog.setOnSaveChangeMiles((selectedTotalItemData, selectedPerItemData, onSaveChangeMiles) -> {
                    mWebView.loadUrl("javascript:updataCarDayMilesBack(" + selectedTotalItemData + "," + selectedPerItemData + ")");
//                    DeleteFriends deleteFriends = new DeleteFriends("Refresh_Crm");
//                    EventBus.getDefault().post(deleteFriends);
                });
                changeMileDialog.showTotalAndTime(totalMile, modelTime, customSet, permile);
            });
        });

        androidJAInteface.setiOnAddPlan(carId -> {
            //添加保养计划
            Bundle bundle = new Bundle();
            bundle.putLong("carId",carId);
            X3RouterCenter.startNavigate(X3AppRouterConstants.Router.WEB_ALONE_SERVICE,bundle);
        });

        // 下载图片资源
        androidJAInteface.setiOnDownFile(this);

        // 标记回访
        androidJAInteface.setiOnClickVisit(this);

        // 预约到店
        androidJAInteface.setiOnClickAppoint(this);

        // 创建接车单
        androidJAInteface.setiOnClickCreate(this);

        // 跳转到聊天页面
        androidJAInteface.setiOnClickMessage(this);

        // 跳转到施工单详情
        androidJAInteface.setiOnClickJumpWork(this);

        // 跳转到现金余额
        androidJAInteface.setiOnClickGiftBalance(this);

//        String fromAssets = getFromAssets("www/receive/receive-detail.html");
//        mWebView.loadDataWithBaseURL("file:///android_asset/", fromAssets, "text/html", "utf-8", null);

        String url = mWebView.getUrl();
        Log.e("QQQ", "webview加载：" + url);
    }


    /*
     * 获取html文件
     */
    public String getFromAssets(String fileName) {
        try {
            InputStreamReader inputReader = new InputStreamReader(
                    getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            String Result = "";
            while ((line = bufReader.readLine()) != null)
                Result += line;
            return Result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    private void goToHomeCamera(String carNumOrVin) {
        String path = X3FileUtils.getStoragePath(this, X3FileUtils.MECHANIC_PHOTO_STORAGE_PATH) + "work_tain" + System.currentTimeMillis() + ".jpg";
        File imageFile = new File(path);
        if (!imageFile.exists()) {
            try {
                imageFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



        if ("carNum".equals(carNumOrVin)) {
            Bundle bundle = new Bundle();
            bundle.putString("path", path);
            bundle.putString("title", getString(R.string.x3_recognize_car_number));
            bundle.putBoolean("type", true);
            X3RouterCenter.startNavigateWithResult(X3GroundPushActivity.this, X3AppRouterConstants.Router.HOME_CAMERA,bundle, X3Constent.CODE_CAMERA_REQUEST);
        }else {
            if(X3Constent.isChina()){
                Bundle bundle = new Bundle();
                bundle.putString("path", path);
                bundle.putString("title", getString(R.string.x3_recognize_vin));
                X3RouterCenter.startNavigateWithResult(X3GroundPushActivity.this, X3AppRouterConstants.Router.HOME_VIN,bundle, X3Constent.CODE_CAMERA_VIN_REQUEST);

            } else {
                Bundle bundle = new Bundle();
                bundle.putString("path", path);
                bundle.putString("title", getString(R.string.x3_recognize_vin));
                X3RouterCenter.startNavigateWithResult(X3GroundPushActivity.this, X3AppRouterConstants.Router.HOME_CAMERA,bundle, X3Constent.CODE_CAMERA_VIN_REQUEST);
            }

        }
    }

    @Override
    public void finish() {
        super.finish();
        Intent intent = new Intent();
        setResult(1,intent);
        overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
    }

    @Override
    protected X3GroundPushPresenter createPresenter() {
        return new X3GroundPushPresenter();
    }

    @Override
    protected void onDestroy() {
        WebViewPool.init(this);
        if (screenRun != null) {
            ThreadPoolManager.getInstance().remove(screenRun);
        }
        getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(mGlobalLayoutListener);
        EventBus.getDefault().unregister(this);
        layout.removeView(mWebView);
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
        super.onDestroy();
        if (mWebView != null) {
            mWebView.destroy();
            mWebView = null;
        }
        if (bottomGiftBalanceDialog != null) {
            bottomGiftBalanceDialog.dismiss();
        }
    }

    @Override
    public void getMyCarList(List<UserCarInfoBean> carInfoBeans, long carOwnerId) {

        if (isAppoint) {
            // 预约到店
            if (appointDialog == null) {
                appointDialog = new X3BottomServiceAppointDialog(this);
            }
            appointDialog.show();
            appointDialog.setiOnClickSelect(this);
            if (appointDialog != null) {
                appointDialog.setCarInfo(carInfoBeans, carOwnerId);
            }
            isAppoint = false;
        }
    }

    /**
     * 预约到店成功 传递给H5
     */
    @Override
    public void saveAppointClueSuccess() {
        loadRefresh();
        X3ToastUtils.showMessage(getString(R.string.x3_appoint_success) + "");
        EventBus.getDefault().post("UPDATE_START_ORDER");
        DeleteFriends deleteFriends = new DeleteFriends("UPDATE_START_ORDER");
        EventBus.getDefault().post(deleteFriends);

        if (appointDialog != null) {
            appointDialog.dismiss();
        }
        if (timeAppointDialog != null) {
            timeAppointDialog.dismiss();
        }
    }

    /**
     * 标记回访Dialog
     */
    @Override
    public void getError() {
        // 隐藏进度条
        hideLoading();
    }

    @Override
    public void getCreditPresentInfoView(GiftBalanceBean giftBalanceBean) {
        //获取赠送余额的数据
        bottomGiftBalanceDialog = new X3BottomGiftBalanceDialog(this);
        bottomGiftBalanceDialog.show();
        bottomGiftBalanceDialog.setData(giftBalanceBean, carOwnerNameUserId);
    }

    @Override
    public void getCarNum(String carNum) {
        mWebView.evaluateJavascript("window.responseCarNumVin(\"carNum\",\"" + carNum + "\")", value -> {});
//        if (lottieShowDialog != null) {
//            lottieShowDialog.setCarNum(carNum);
//        }
    }

    @Override
    public void getVin(String vin) {
        if (X3StringUtils.isEmpty(vin)) {
            X3ToastUtils.showMessage("" + getString(R.string.x3_no_recognize_vin));
            return;
        }
        mWebView.evaluateJavascript("window.responseCarNumVin(\"carVin\",\"" + vin + "\")", value -> {});
//        if (lottieShowDialog != null) {
//            lottieShowDialog.setCarVin(vin);
//        }
        if(homeCarDialog != null){
            homeCarDialog.setVin(vin);
        }
    }

    @Override
    public void iOnClickVisit(String markStr) {
        runOnUiThread(() -> {

            if (X3Utils.isFastClick()) {
                pushBean = gson.fromJson(markStr, GroundPushBean.class);
                if (pushBean == null) {
                    return;
                }
                carListId = pushBean.getCarListId();
                if (X3StringUtils.isEmpty(carListId)) {
                    return;
                }

                CarOwnerDaoBean visitBean = new CarOwnerDaoBean();
                visitBean.setCarOwnerUserId(Integer.parseInt(pushBean.getCarListId()));
                visitBean.setMobile(pushBean.getMobile());
                visitBean.setAreaCode(pushBean.getAreaCode());
                XXPermissions.with(this)
                        .permission(Permission.SYSTEM_ALERT_WINDOW)
                        .request(new OnPermissionCallback() {
                            @Override
                            public void onGranted(List<String> permissions, boolean all) {
                                if(all){
                                    if (FloatWindow.get("Visit") != null) {
                                        X3ToastUtils.showMessage(getString(R.string.x3_current_mobile_not_end));
                                        return;
                                    }
                                    Bundle bundle = new Bundle();
                                    bundle.putSerializable("visit",visitBean);
                                    X3RouterCenter.startNavigate(X3AppRouterConstants.Router.MAIN_VISIT,bundle);

                                }else {
                                    XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                                }
                            }

                            @Override
                            public void onDenied(List<String> permissions, boolean never) {
                                XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                            }
                        });
            }
        });
    }

    @Override
    public void iOnJumpToMessage(String carUserId, String userName) {
        if (X3Utils.isFastClick()) {
            if ("0".equals(carUserId)) {
                X3ToastUtils.showMessage(getString(R.string.x3_user_no_exist) + "");
                return;
            }
            try {
                //直接跳转聊天
                Bundle bundle = new Bundle();
                bundle.putInt("type",1);
                bundle.putString("id",carUserId);
                bundle.putString("name",userName);
                X3RouterCenter.startNavigate(X3AppRouterConstants.Router.MAIN_MESSAGE,bundle);

//                ChatInfo chatInfo = new ChatInfo();
//                chatInfo.setType(V2TIMConversation.V2TIM_C2C);
//                chatInfo.setId(carUserId);
//                chatInfo.setChatName(userName);
//                Intent intent = new Intent(GroundPushActivity.this, IMMessageActivity.class);
//                intent.putExtra(Constants.CHAT_INFO, chatInfo);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);

            } catch (Exception e) {

            }
        }
    }

    @Override
    public void onBackPressed() {
        if (!isEnable) {
            if (mWebView.canGoBack()) {
                mWebView.goBack();
            } else {
                finish();
            }
        }
    }

    @Override
    public void iOnClickJumpAppoint(String appointStr) {
        if (X3StringUtils.isEmpty(appointStr)) {
            X3ToastUtils.showMessage(getString(R.string.x3_user_info_notall) + "");
            return;
        }
        if (X3Utils.isFastClick()) {
            AppointBean appointBean = gson.fromJson(appointStr, AppointBean.class);
            if (appointBean == null) {
                X3ToastUtils.showMessage(getString(R.string.x3_user_info_notall) + "");
                return;
            }
            mobile = appointBean.getMobile();
            isAppoint = true;

            if (mPresenter != null) {
                mPresenter.getCarList(Integer.parseInt(appointBean.getCarOwnerUserId()));
            }
        }
    }

    @Override
    public void iOnClickSelectCar(AppointClueBean clueBean) {
        if (clueBean == null) {
            X3ToastUtils.showMessage(getString(R.string.x3_no_get_car_info) + "");
            return;
        }
        // 预约到店选择车辆
        timeAppointDialog = new X3BottomTimeAppointDialog(this);
        timeAppointDialog.show();
        timeAppointDialog.setAppointClue(clueBean);
        timeAppointDialog.setiOnClickTime(this);

    }

    @Override
    public void iOnClickTimeAppoint(AppointClueBean clueBean) {
        clueBean.setMobile(mobile);
        // 预约到店
        if (mPresenter != null) {
            mPresenter.saveAppointClue(clueBean);
        }
    }

    @Override
    public void iOnClickJumpToWork(String serviceBase) {
        if (X3StringUtils.isEmpty(serviceBase)) {
            X3ToastUtils.showMessage(getString(R.string.x3_no_work_id) + "");
            return;
        }

        JumpToWorkBase jumpToWorkBase = new Gson().fromJson(serviceBase, JumpToWorkBase.class);

        if (X3StringUtils.isEmpty(jumpToWorkBase.getId())) {
            X3ToastUtils.showMessage(getString(R.string.x3_no_work_id) + "");
            return;
        }

        EventBus.getDefault().post("UPDATE_START_ORDER");

        if ("DETECTION".equals(jumpToWorkBase.getServiceCategoryName())) {
            Bundle bundle = new Bundle();
            bundle.putLong("id",Long.parseLong(jumpToWorkBase.getId()));
            bundle.putLong("receiveBaseId",Long.parseLong(jumpToWorkBase.getReceiveBaseId()));
            X3RouterCenter.startNavigate(X3AppRouterConstants.Router.MAIN_TAIN,bundle);
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putLong("id",Long.parseLong(jumpToWorkBase.getId()));
        bundle.putLong("receiveBaseId",Long.parseLong(jumpToWorkBase.getReceiveBaseId()));
        X3RouterCenter.startNavigate(X3AppRouterConstants.Router.MAIN_SIVE,bundle);

        try {
            if (X3StringUtils.isListEmpty(X3MyApp.mActivities)) {

                return;
            }
            mWebView.post(() -> {

                int flag = 0;
                for (int i = 0; i < X3MyApp.mActivities.size(); i++) {
                    if (X3MyApp.mActivities.get(i) instanceof X3GroundPushActivity) {
                        flag++;
                        if (flag > 1) {
                            X3MyApp.mActivities.get(i).finish();
                        } else {
                            ((X3GroundPushActivity) X3MyApp.mActivities.get(i)).loadRefresh();
                        }
                    }
                }

            });

        }catch (Exception e) {

        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        switch (requestCode) {
            case CREATE_TASK_START:
                // 创建待办事项成功
                mWebView.evaluateJavascript("window.creatNextComplete()", value -> {});
                break;
            case X3Constent.CODE_CAMERA_REQUEST:
                String filePath = data.getStringExtra("path");
                Luban.with(this)
                        .load(filePath)
                        .ignoreBy(100)
                        .setTargetDir(X3FileUtils.getStoragePath(this, X3FileUtils.MECHANIC_PHOTO_STORAGE_PATH))
                        .filter(path -> !(TextUtils.isEmpty(filePath) || filePath.toLowerCase().endsWith(".gif")))
                        .setCompressListener(new OnCompressListener() {
                            @Override
                            public void onStart() {

                            }

                            @Override
                            public void onSuccess(File file) {
                                if (mPresenter != null) {
                                    mPresenter.requestCarNum(file);
                                }
                            }

                            @Override
                            public void onError(Throwable e) {

                            }
                        }).launch();

                break;
            case X3Constent.CODE_CAMERA_VIN_REQUEST:
                if(X3Constent.isChina()){
                    String vin = data.getStringExtra("vinResult");
//                this.showLoading("");
                    System.out.println("识别vin码"+vin);
                    mWebView.post(new Runnable() {
                        @Override
                        public void run() {
                            mWebView.evaluateJavascript("window.responseCarNumVin(\"carVin\",\"" + vin + "\")", value -> {});
                        }
                    });
                }else {
                    String vinPath = data.getStringExtra("path");
                    Luban.with(this)
                            .load(vinPath)
                            .ignoreBy(100)
                            .setTargetDir(X3FileUtils.getStoragePath(this, X3FileUtils.MECHANIC_PHOTO_STORAGE_PATH))
                            .filter(path -> !(TextUtils.isEmpty(vinPath) || vinPath.toLowerCase().endsWith(".gif")))
                            .setCompressListener(new OnCompressListener() {
                                @Override
                                public void onStart() {

                                }

                                @Override
                                public void onSuccess(File file) {
                                    if (mPresenter != null) {
                                        mPresenter.requestVin(file);
                                    }
                                }

                                @Override
                                public void onError(Throwable e) {

                                }
                            }).launch();
                }
                break;
            case 3333:
                String filePath3 = data.getStringExtra("path");
                // 调用reloadpage
                try {
                    if (X3StringUtils.isEmpty(filePath3)) {
                        return;
                    }
                    reloadStr = filePath3.replace("\"", "\'");
                    mWebView.post(new Runnable() {
                        @Override
                        public void run() {
                            mWebView.evaluateJavascript("window.reloadPage(\"" + reloadStr + "\")", value -> Log.e("调用reloadPagevalue", value + "-----"));
                        }
                    });

                }catch (Exception e) {

                }
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(DeleteFriends content) {
        String type = content.getType();
        switch (type) {
            case "UPDATE_CNACEL_ORDER":
                finish();
                break;
            case "EVENBUSTIPS":
                //赠送余额成功之后的回调
                finish();
                break;
            case "EVENBUSRES":
                //刷新数据，1、标记回访  2、赠送余额成功之后
                mWebView.evaluateJavascript("window.markAfterAskComplete()", value -> {
                });
                break;
            case "REFRESH_TASK":
                mWebView.evaluateJavascript("window.creatNextComplete()", value -> {});
                break;
            case "CAR_BIND":
                // 帮助车主绑定车辆
                mWebView.evaluateJavascript("window.reloadPage(\"" + 0 + "\")", value -> {});
                break;
            case "CREATE_TASK_START":
                // 修改或者新建待办事项
                mWebView.evaluateJavascript("window.creatNextComplete()", value -> {});
                break;
            case "CarCut":
                // 车辆切割
                // 这里是首页创建接车单修改缩略图
                String imgPath = content.getImgPath();
                long carId = content.getCarId();
                String carNum = content.getCarNum();
                if (X3StringUtils.isEmpty(imgPath)) {
                    return;
                }
                if (imgPath.equals(lastCutPath)) {
                    return;
                }
                this.lastCutPath = imgPath;
                this.reloadStr = imgPath;
                X3ToastUtils.showMessage(getString(R.string.x3_upload_car_cut_notice));
                if (picAndColorDialog != null) {
                    picAndColorDialog.changeCarCutImage(imgPath + "");
                    // 上传首页创建的缩略图 切割
                    if (mPresenter != null) {
                        mPresenter.uploadCarPic(carId,imgPath,carNum);
                    }
                }
                if (homeCarDialog != null) {
                    homeCarDialog.changeLastCarCut(imgPath + "");
                    // 上传首页创建的缩略图 切割
                    if (mPresenter != null) {
                        mPresenter.uploadCarPic(carId,imgPath,carNum);
                    }
                }

                break;
                //添加完保养计划
            case "REFRESH_GROUND":
                loadRefresh();
                break;
        }
    }

    @Override
    public void iOClickGiftBalance(String carOwnerUserId) {
        //跳转到赠送余额
        // 赠送余额
        if (X3Utils.isFastClick()) {
            carOwnerNameUserId = Integer.parseInt(carOwnerUserId);
            if (mPresenter != null) {
                mPresenter.getCreditPresentInfo(carOwnerNameUserId);
            }
        }
    }

    @Override
    public void iOnClickCeateTask(String taskStr) {

    }

    @Override
    public void iOnDownLoadFile(String path) {
        /**
         * 下载H5展示的图片
         */
        Log.e("SSSS","下载文件:" + path);
        X3FileUtils.saveImageUrlToGallery(this, path, new X3FileUtils.OnListener() {
            @Override
            public void onSuccess() {
                X3ToastUtils.showMessage(getString(R.string.x3_download_success));
            }

            @Override
            public void onFail() {
                X3ToastUtils.showMessage(getString(R.string.x3_download_fail));
            }
        });
    }

    /**
     * 刷新当前页面
     */
    public void loadRefresh() {
        try {
            mWebView.postDelayed(() -> {
                if (isFinishing() || mWebView == null) {
                    return;
                }
                mWebView.evaluateJavascript("window.reloadPage(\"" + 0 + "\")", value -> {});
            },200);
        }catch (Exception e) {

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(X3StringUtils.isEmpty(title)){
            MobclickAgent.onPageStart(title);
        }
        DeleteFriends deleteFriends = new DeleteFriends("Refresh_Service");
        EventBus.getDefault().post(deleteFriends);
        if (X3StringUtils.isEmpty(reloadStr)) {
            loadRefresh();
        }else {
            try {
                mWebView.postDelayed(() -> {
                    if (mWebView == null) {
                        return;
                    }
                    mWebView.evaluateJavascript("window.reloadPage(\"" + reloadStr + "\")", value -> {
                    });
                    reloadStr = "";
                },1000);
            }catch (Exception e) {

            }
        }
        if (mWebView != null && mWebView.getSettings() != null) {
            mWebView.getSettings().setJavaScriptEnabled(true);
            //初始化的时候设置，具体代码在WebView类中
            if(Build.VERSION.SDK_INT >= KITKAT) {
                //设置网页在加载的时候暂时不加载图片
                mWebView.getSettings().setLoadsImagesAutomatically(true);
            } else {
                mWebView.getSettings().setLoadsImagesAutomatically(false);
            }

            //启用或禁用应用缓存
            mWebView.getSettings().setAppCacheEnabled(true);
            mWebView.getSettings().setDatabaseEnabled(true);
            mWebView.getSettings().setDomStorageEnabled(true);//开启DOM缓存
            mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

            //开启硬件加速
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
        }

        if (taskInput != null) {
            taskInput.hideRlInputBottom();
        }
    }

    public Handler mHandler = new Handler() {
        @SuppressLint("HandlerLeak")
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {
                String obj = (String) msg.obj;
                if (X3StringUtils.isEmpty(obj)) {
                    return;
                }
                if (!X3StringUtils.isNum(obj)) {
                    return;
                }
                int carId = Integer.parseInt(obj);
                if (mPresenter != null) {
                    mPresenter.getCarMechanic(carId);
                }
            }else if(msg.what == 1){
                cuteNum++;
                if (picAndColorDialog != null && cuteNum >= allNum * 5) {
                    X3BottomHomeCarAndColorAdapter bottomHomeCarAndColorAdapter = picAndColorDialog.getBottomHomeCarAndColorAdapter();
                    if (bottomHomeCarAndColorAdapter != null) {
                        bottomHomeCarAndColorAdapter.notifyDataSetChanged();
                    }
                }

            }else if (msg.what == 2) {
                screenGetBitmap();

            }else if (msg.what == 3) {
                X3ToastUtils.showMessage(getString(R.string.x3_keep_success));
                viewProxy.hideLoading();
                mWebView.evaluateJavascript("window.screenComplete()", s -> {
                });
            }
        }
    };

    @Override
    public void getCarForMechanic(CarPropertiesBean propertiesBean, long carId) {
    }

    @Override
    public void downSuccess() {
        Message msg = Message.obtain();
        msg.what = 1;
        mHandler.sendMessage(msg);
    }

    @Override
    public void saveOilSuccess() {
        mWebView.evaluateJavascript("window.nativeEditFirstVOBack()", value -> {});
    }

    @Override
    public void getReceiveBase(HomeMainCarBean mainCarBean) {
        this.detectionFirstOrNot = mainCarBean.isDetectionFirstOrNot();
        if (mainCarBean == null) {
            return;
        }
        if (homeCarDialog != null && isShow ) {
            homeCarDialog.changeHomeMainData(mainCarBean);
        }
    }

    @Override
    public void updateCarTypeSuccess() {
        DeleteFriends deleteFriends = new DeleteFriends("REFRESH_GROUND");
        EventBus.getDefault().post(deleteFriends);
        mWebView.evaluateJavascript("window.updateCarType()", value -> {});
    }

    @Override
    public void downCarPicSuccess(List<CarPicAndColorBean> picList,String carNum,long colorId,long carPicTempletId) {
        this.carPicList = picList;
        if (X3StringUtils.isListEmpty(carPicList)) {
            CarPicAndColorBean picAndColorBean = new CarPicAndColorBean();
            picAndColorBean.setWaitingForCarPicTemplet(false);

            String replace = picAndColorBean.toString().replace("\"", "\'");

            mWebView.evaluateJavascript("window.setCarPic(\"" + replace + "\")",
                    value -> Log.e("调用setCarPic", value + "-----"));

            carPicList = new ArrayList<>();
            carPicList.add(new CarPicAndColorBean());
            if (picAndColorDialog != null) {
                picAndColorDialog.changeCarAndPic(carPicList,carNum,0,0);
            }
        }else if (carPicList.size() == 1) {
            CarPicAndColorBean picAndColorBean = carPicList.get(0);
            String carNum1 = picAndColorBean.getCarNum();

            if (X3StringUtils.isEmpty(carNum1)) {
                String replace = picAndColorBean.toString().replace("\"", "\'");

                mWebView.evaluateJavascript("window.setCarPic(\"" + replace + "\")",
                        value -> Log.e("调用setCarPic", value + "-----"));
            }else {
                carPicList.add(0,new CarPicAndColorBean());
            }
            if (picAndColorDialog != null) {
                picAndColorDialog.changeCarAndPic(carPicList,carNum,colorId,carPicTempletId);
            }
        }else {
            XXPermissions.with(X3GroundPushActivity.this)
                    .permission(Permission.Group.STORAGE)
                    .request(new OnPermissionCallback() {
                        @Override
                        public void onGranted(List<String> permissions, boolean all) {
                            if(all){
                                downCarPicAndColor(picList,carNum,colorId,carPicTempletId);
                            }else{
                                XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                            }
                        }

                        @Override
                        public void onDenied(List<String> permissions, boolean never) {
                            XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                        }
                    });
        }
    }

    @Override
    public void uploadCarPicSuccess(CarPicAndColorBean colorBean) {
        if (colorBean == null) {
            X3ToastUtils.showMessage(getString(R.string.x3_car_cut_fail));
            if (picAndColorDialog != null) {
                picAndColorDialog.changeLastCarAndPic(null);
            }
            if (homeCarDialog != null) {
                homeCarDialog.changeLastCarCut(null);
            }
        }else {
            if (picAndColorDialog != null) {
                picAndColorDialog.changeLastCarAndPic(colorBean);
            }else if (homeCarDialog != null) {
                homeCarDialog.uploadCarCutSuccess(colorBean);
            } else {
                X3ToastUtils.showMessage(getString(R.string.x3_car_cut_success));
            }
        }
    }

    @Override
    public void saveCommunSuccess() {
        // TODO 通知H5保存留言成功
//        et_input.setText("");
        X3ToastUtils.showMessage(getString(R.string.x3_commun_success));
        DeleteFriends deleteFriends = new DeleteFriends("REFRESH_GROUND");
        EventBus.getDefault().post(deleteFriends);
        mWebView.evaluateJavascript("window.nativeLeaveMsgBack()", value -> {});
    }

    /**
     * 获取屏幕截图
     */
    private void screenGetBitmap() {
        if (shareDialog == null) {
            shareDialog = new X3TipsDialog(this,getString(R.string.share_report));
        }
        shareDialog.show();

        mWebView.evaluateJavascript("document.getElementById('screen-id').offsetHeight", value -> {
            captureHeight = value;
            if (!X3StringUtils.isEmpty(captureHeight)) {
                ThreadPoolManager.getInstance().execute(screenRun);
            }else {
                if (shareDialog != null) {
                    shareDialog.dismiss();
                }
            }
        });
    }

    private Runnable screenRun = new Runnable() {
        @Override
        public void run() {
            // 精简版
            if (X3StringUtils.isEmpty(captureHeight)) {
                ThreadPoolManager.getInstance().remove(screenRun);
                return;
            }
            mWebView.scrollTo(0, 0);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (isFinishing()) {
                return;
            }
            if (mWebView == null) {
                return;
            }
            Bitmap webViewBitmap = X3BitmapUtils.getWebViewBitmap(captureHeight, X3GroundPushActivity.this,mWebView);
            String path = X3FileUtils.getStoragePath(X3GroundPushActivity.this, X3FileUtils.MECHANIC_SCREEN_SHOT_STORAGE_PATH);
            String s = X3FileUtils.saveBitmap(path, System.currentTimeMillis() + ".png", webViewBitmap);
            mWebView.post(() -> {
                if (shareDialog != null) {
                    shareDialog.dismiss();
                }
                mWebView.evaluateJavascript("window.screenComplete()", s1 -> {});
                Intent intent = new Intent(X3GroundPushActivity.this, X3ReportActivity.class);
                intent.putExtra("path",s);
                intent.putExtra("aloneShareBean", aloneShareParamsBean);
                X3GroundPushActivity.this.startActivity(intent);
                X3GroundPushActivity.this.overridePendingTransition(R.anim.activity_top_enter,0);

            });
            ThreadPoolManager.getInstance().remove(screenRun);

        }
    };

    @Override
    public void iOnClikCameraVin() {
        XXPermissions.with(this)
                .permission(Permission.CAMERA)
                .permission(Permission.Group.STORAGE)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        if(all){
                            String   path = X3FileUtils.getStoragePath(X3GroundPushActivity.this, X3FileUtils.MECHANIC_PHOTO_STORAGE_PATH) + "work_tain" + System.currentTimeMillis() + ".jpg";
                            if(X3Constent.isChina()){
                                Bundle bundle = new Bundle();
                                bundle.putString("path", path);
                                bundle.putString("title", getString(R.string.x3_recognize_vin));
                                X3RouterCenter.startNavigateWithResult(X3GroundPushActivity.this, X3AppRouterConstants.Router.HOME_VIN,bundle, X3Constent.CODE_CAMERA_VIN_REQUEST);

                            } else {
                                Bundle bundle = new Bundle();
                                bundle.putString("path", path);
                                bundle.putString("title", getString(R.string.x3_recognize_vin));
                                X3RouterCenter.startNavigateWithResult(X3GroundPushActivity.this, X3AppRouterConstants.Router.HOME_CAMERA,bundle, X3Constent.CODE_CAMERA_VIN_REQUEST);

                            }

                        }else {
                            XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                        }
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        XXPermissions.startPermissionActivity(X3GroundPushActivity.this,permissions);
                    }
                });
    }

    @Override
    public void iOnClickCarBtnNext(CarSelectBean selectBean) {
        if (homeCarDialog != null) {
            homeCarDialog.dismiss();
        }
        if (mPresenter != null) {
            mPresenter.updateReceiveCar(selectBean,carNum);
        }
    }

    @Override
    public void iOnClickDismiss(long receiveId) {

    }

    @Override
    public void iOnCancelCurrentPage() {
        finish();
    }

    /**
     * 获取车辆品牌的数据
     */
    private void getCarBrandData() {
        brandSelectDialog = new X3HomeBrandSelectDialog(this);
        brandSelectDialog.show();
        brandSelectDialog.setiOnClick(new X3HomeBrandSelectDialog.IOnClickCar() {
            @Override
            public void iOnClickSelect(CarBrandBean brandBean, boolean isSearchStyle) {
                if (infoBean == null) {
                    return;
                }
                if (isSearchStyle){
                    mWebView.evaluateJavascript("window.showVehicleInfoSuccess(\"" + infoBean.type + "\",\"" + brandBean.getLabel() + "\",\"" + brandBean.getValue() + "\")", value -> {});
                    CarBrandBean brandBean2 = new CarBrandBean();
                    brandBean2.setLabel(brandBean.getStyleName());
                    brandBean2.setValue(brandBean.getCarStyleId());
                    styleSelected(brandBean2);
                } else {
                    getCarYearData(brandBean);
                    mWebView.evaluateJavascript("window.showVehicleInfoSuccess(\"" + infoBean.type + "\",\"" + brandBean.getLabel() + "\",\"" + brandBean.getValue() + "\")", value -> {});
                }
                brandSelectDialog.dismiss();

            }
        });

        //获取车辆品牌
        NetWorkHttp.getApi().showCarBrandAndCommonUse()
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .subscribe(new HttpCallBack<CarBrandAndCommonBean>() {
                    @Override
                    protected void onDone(CarBrandAndCommonBean carBrandBeans) {
                        if (carBrandBeans == null) {
                            X3ToastUtils.showMessage(getString(R.string.x3_home_no_select));
                            return;
                        }
                        brandList = carBrandBeans.list;
                        if (X3StringUtils.isListEmpty(brandList)) {
                            // 这里是为了防止频繁的打开Dailog出现数组越界的问题
                            X3ToastUtils.showMessage(getString(R.string.x3_home_no_select));
                            return;
                        } else {
                            if (brandSelectDialog != null) {
                                List<CarModelSelectBean> selectLists = new ArrayList<>();
                                brandSelectDialog.changeData(getString(R.string.x3_brand),brandList,carBrandBeans.commonList,selectLists);
                            }
                        }
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    /**
     * 获取车款
     */
    private void getCarYearData(CarBrandBean brandBean) {
        if (styleSelectDialog == null) {
            styleSelectDialog = new X3HomeStyleSelectDialog(this);
        }
        styleSelectDialog.show();
        styleSelectDialog.setiOnClick(brandBean1 -> {
            if (brandBean1 == null) {
                return;
            }
            if (getString(R.string.x3_home_no_select).equals(brandBean1.getLabel())) {
                return;
            }

            if (brandBean1 == null) {
                return;
            }
            styleSelected(brandBean1);
        });

        //获取车款
        NetWorkHttp.getApi().receiveShowCarStyle(Integer.parseInt(brandBean.getValue()))
                .compose(((X3IBaseView) this).bindToLife())
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .subscribe(new HttpCallBack<List<CarBrandBean>>() {
                    @Override
                    protected void onDone(List<CarBrandBean> carBrandBeans) {
                        carStyleList = carBrandBeans;
                        if (X3StringUtils.isListEmpty(carStyleList)) {
                            //这里是为了防止出现数组越界的BUG
                            carStyleList.add(new CarBrandBean(getString(R.string.x3_home_no_select), "0"));
                        }

                        if (styleSelectDialog != null) {
                            styleSelectDialog.changeData(getString(R.string.x3_models) + "",
                                    carStyleList, "", brandBean.getLabel());
                        }
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    private void styleSelected(CarBrandBean brandBean1){
        String styleName = "";
        String styleId = "";

        if (getString(R.string.x3_home_no_select).equals(brandBean1.getLabel())) {
            styleName = "";
            styleId = "";
        }else {
            styleName = brandBean1.getLabel();
            styleId = brandBean1.getValue();
        }
        if (styleSelectDialog != null) {
            styleSelectDialog.dismiss();
        }

        mWebView.evaluateJavascript("window.showVehicleInfoSuccess(\"" + "carStyle" + "\",\"" + styleName + "\",\"" + styleId + "\")", value -> {});

    }

    @Override
    public void iOnClickSelect(String year, String month,String zhMonth) {
        if (infoBean == null) {
            return;
        }
        boolean zhRCN = LanguageUtiles.isZhRCN();
        String carTime = "";

        if (zhRCN) {
            carTime = year + "-" + month;
        }else {
            carTime = month + ", " + year;
        }
        String zhCarTime = year + "-" + zhMonth;

        mWebView.evaluateJavascript("window.showVehicleInfoSuccess(\"" + infoBean.type + "\",\"" + carTime + "\",\"" + zhCarTime + "\")", value -> {});
    }


    /**
     * 请求车款缩略图和图片
     * @param carId
     * @param carStyleId
     */
    private void getCarPicAndColor(long carId, long carStyleId,String carNum,long colorId,long carPicTempletId) {
        HashMap<String,Object> map = new HashMap<>();
        if (carId > 0) {
            map.put("carId",carId);
        }
        if (!X3StringUtils.isEmpty(carNum)) {
            map.put("carNum",carNum);
        }
        if (carStyleId > 0) {
            map.put("carStyleId",carStyleId);
        }
        if (mPresenter != null) {
            mPresenter.showCarPicAndColor(map,carNum,colorId,carPicTempletId);
        }
    }

    private void downCarPicAndColor(List<CarPicAndColorBean> mList,String carNum,long colorId,long carPicTempletId) {
        allNum = 0;
        cuteNum = 0;
        for (int i = 0; i < mList.size(); i++) {
            String type = mList.get(i).getType();
            String colourRgb = mList.get(i).getColourRgb();
            if ("T_JSON".equals(type)) {
                X3FileUtils.saveBitmap(X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb + "/images", "img_6.png", img_6);

                // 移动动画
                String moveUrl = mList.get(i).getMoveJsonResourceUrl();
                // 轮胎
                String tyreUrl = X3StringUtils.getImageUrl(mList.get(i).getTyreResourceUrl());
                // 刹车盘
                String brakeUrl = X3StringUtils.getImageUrl(mList.get(i).getBrakeResourceUrl());
                // 亮色车身颜色
                String colorUrl = X3StringUtils.getImageUrl(mList.get(i).getPicUrl());

                if (!X3StringUtils.isEmpty(moveUrl)&& !X3StringUtils.isEmpty(mList.get(i).getTyreResourceUrl())
                        && !X3StringUtils.isEmpty(mList.get(i).getBrakeResourceUrl()) &&
                        !X3StringUtils.isEmpty(mList.get(i).getPicUrl()) && mPresenter != null) {
                    allNum++;
                    mPresenter.downloadDropFile(moveUrl, X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb);

                    mPresenter.downCarJsonImageUrl(X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb + "/images",
                            tyreUrl, "img_2.png");

                    mPresenter.downCarImageUrl(X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb + "/images",
                            colorUrl, "img_4.png");

                    mPresenter.downCarImageUrl(X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb + "/images",
                            brakeUrl, "img_3.png");

                    mPresenter.downCarImageUrl(X3FileUtils.getStoragePath(this, X3FileUtils.CAR_STORAGE_PATH) + carNum + colourRgb + "/images",
                            colorUrl, "img_5.png");

                }

            }
        }

        if (picAndColorDialog != null) {
            picAndColorDialog.hidePrograssBar();
            picAndColorDialog.changeCarAndPic(mList,carNum,colorId,carPicTempletId);
        }
    }

    @Override
    public void iOnSendContent(String content,String type) {
        switch (type) {
            case "lastName":
            case "nickname":
            case "home":
            case "workPlace":
                if (inputBean == null) {
                    return;
                }
                inputBean.value = content;
                mWebView.evaluateJavascript("window.inputContentChangeBack(" + inputBean.toString() + ")", value -> {});

                break;
            default:
                if (mPresenter != null) {
                    mPresenter.saveCommun(carowneruserCommunicationId,content);
                }
                break;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if(X3StringUtils.isEmpty(title)){
            MobclickAgent.onPageEnd(title);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mWebView != null) {
            mWebView.getSettings().setJavaScriptEnabled(false);
        }
        isShow = false;
    }

    @Override
    public void iOnRefreshPlan() {
        DeleteFriends deleteFriends = new DeleteFriends("REFRESH_GROUND");
        EventBus.getDefault().post(deleteFriends);
        mWebView.evaluateJavascript("window.showChangePlanBack()", value -> {});
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onColseSelf(CloseWebviewAcivityBean bean) {
        finish();
    }

    @Override
    public void onProgressChange(int progress) {
        if (psb == null){
            return;
        }
        psb.setProgress(progress);
        if (progress == 100) {
            psb.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPageStarted() {
        if (psb == null){
            return;
        }
        psb.setVisibility(View.VISIBLE);
    }
}

